import Koa from 'koa';
import Router from 'koa-router';
import bodyParser from 'koa-bodyparser';
import cors from '@koa/cors'
import { appPort } from './config/setting.js';
import { sync } from './model/Store.js';
import { registerRouter } from './router/storeRouter.js';

const app = new Koa();
const router = new Router();

//解析前段数据
app.use(bodyParser());

//注册路由
registerRouter(router)
//解决跨域
app.use(cors());

//同步数据库
sync()
//自动注册路由
app.use(router.routes());

//监听
app.listen(appPort)
console.log(`服务器运行地址为:http://localhost:${appPort}`);
